package com.example.demo.work.util;

import java.io.Serializable;

public class Pager implements Serializable {

    private static final long serialVersionUID = -8741766802354222579L;

    //每页显示多少条记录
    private int pageSize = 2000;
    //当前第几页数据
    private int currentPage;
    //一共有多少条记录
    private int totalCount;
    //一共多少页记录
    private int totalPage;
    //当前页起始索引
    private int fromIndex;
    //当前页的结束索引
    private int toIndex;

    public Pager() {
        super();
    }

    public Pager(int pageNum, int totalCount) {
        //总记录条数
        this.totalCount = totalCount;
        //获取总页数
        this.totalPage = this.totalCount / this.pageSize;
        if (this.totalCount % this.pageSize != 0) {
            this.totalPage += 1;
        }

        //当前第几页数据
        this.currentPage = this.totalPage < pageNum ? this.totalPage : pageNum;
        //起始索引
        this.fromIndex = this.pageSize * (this.currentPage - 1);
        //结束索引
        this.toIndex = this.pageSize * this.currentPage > this.totalCount ? this.totalCount : this.pageSize * this.currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public int getFromIndex() {
        return fromIndex;
    }

    public void setFromIndex(int fromIndex) {
        this.fromIndex = fromIndex;
    }

    public int getToIndex() {
        return toIndex;
    }

    public void setToIndex(int toIndex) {
        this.toIndex = toIndex;
    }
}
